<!--
 * @Author: gao_m3
 * @Date: 2020-11-02 10:31:25
 * @LastEditors: wei_jt@ecidi.com
 * @LastEditTime: 2022-03-31 10:53:20
 * @Descripttion: 
-->
<template>
  <div class="drawer-container">
    <div class="item-container">
      <fks-tabs v-model="serverType" type="card" style="margin-top: 24px">
        <fks-tab-pane :label="LANG.MAIL" name="mailServerConfig">
          <mail-server
            :mail-server-config="mailServerConfig"
            :update-config="updateConfig"
          />
        </fks-tab-pane>
        <fks-tab-pane :label="LANG.SMS" name="smsServerConfig">
          <sms-server
            :sms-server-config="smsServerConfig"
            :update-config="updateConfig"
          />
        </fks-tab-pane>
        <fks-tab-pane
          :label="LANG.FILE"
          name="fileServerConfig"
          class="fileTab"
        >
          <file-server
            :file-server-config="fileServerConfig"
            :update-config="updateConfig"
          />
        </fks-tab-pane>
      </fks-tabs>
    </div>
  </div>
</template>

<script>
import { deepClone } from '@/utils/util'
import Mix from '@/mixins/module'
import MailServer from './components/MailServer'
import SmsServer from './components/SmsServer'
import FileServer from './components/FileServer'
import { getServerConfig, setServerConfig } from '../api'

export default {
  name: 'Server',
  components: { MailServer, SmsServer, FileServer },
  mixins: [Mix],
  data() {
    return {
      serverType: 'mailServerConfig',
      smsServerConfig: [],
      mailServerConfig: [],
      fileServerConfig: {},
      initData: {}
    }
  },
  mounted() {
    this.init()
  },
  methods: {
    serverAdd() {},

    init() {
      getServerConfig()
        .then((res) => {
          if (res.status) {
            this.smsServerConfig = res.data.smsServerConfig
            this.mailServerConfig = res.data.mailServerConfig
            this.fileServerConfig = res.data.fileServerConfig
            this.initData = deepClone(res.data)
          }
        })
        .catch(() => {})
    },

    /**
     * @description: 更新服务器配置的回调
     */
    updateConfig(config, init) {
      let params = {
        ...this.initData,
        ...config
      }
      return setServerConfig(params)
        .then((res) => {
          if (!res.status) {
            this.init()
          }
          return res
        })
        .catch(() => {})
    }
  }
}
</script>

<style lang="scss" scoped>
.drawer-container {
  width: 100%;
  min-width: 648px;
  height: 100%;
  padding: 28px;
  overflow-y: auto;
  background-color: white !important;

  .item-container {
    width: 100%;
  }
}
</style>